package com.lihao.sam.controller;

import com.lihao.sam.entity.CheckIn;
import com.lihao.sam.service.intf.CheckInService;
import com.lihao.sam.vo.PageVo;
import com.lihao.sam.vo.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * *  作者:陈国强
 * *  日期:2022/11/23 11:45
 * *  文件描述:住宿登记持久层
 */
@RestController
@RequestMapping("/api/checkIn/")
public class CheckInController {
    @Resource
    private CheckInService service;
    @PostMapping("add.do")
    public R add(CheckIn checkIn){
        return service.addTX(checkIn);
    }
    @PostMapping("update.do")
    public R update(CheckIn checkIn){
        return service.update(checkIn);
    }
    @PostMapping("delete.do")
    public R delete(int id, HttpSession session){
        return service.delete(id);
    }
    @PostMapping("deletebatch.do")
    public R deleteBatch(int[] ids) {
        return service.delBatch(ids);
    }
    @GetMapping("page.do")
    public PageVo page(Integer id,String stuId, String name, int page, int limit){
        return service.queryPage(id, stuId, name,page, limit);
    }
    /**
     * 实现文件上传数据的导入*/
    @PostMapping("upload.do")
    public R upload(MultipartFile file){
        //1.获取文件上传的内容
        //2.处理文件内容，得到集合
        //3.实现批量新增
        return service.importData(file);
    }

    /**
     * 实现下载数据*/
    @GetMapping("download.do")
    public void download(HttpServletResponse response) throws IOException {
        service.exportData(response);
    }
}
